package twentytwentyone_3;

/**
 * @Author: Zahi
 * @Description:
 * @Date Created in 2021-03-08 15:28
 * @Modified By:
 */
public class ConvertToBase7_504 {

    public static void main(String [] args){
        System.out.println(convertToBase7(100));
    }

    public static String convertToBase7(int num) {
        StringBuilder result = new StringBuilder();
        // 特殊条件判断
        if (num == 0){
            return "0";
        }
        boolean flag = false;
        // 判断给的数字是否小于0 转换为正数处理
        if (num < 0){
            num = -num;
            flag = true;
        }
        // 进制转换模板，先求余再求商
        while (num != 0){
            result.append(num % 7);
            num /= 7;
        }
        if (flag) result.append("-");
        result.reverse();
        return result.toString();
    }
}
